package com.open4cn.simulator.core.connector;

import com.open4cn.simulator.core.exception.IllegalParameterException;

/**
 * @author yinxiaopeng
 * @version 1.0.0
 * @company 致景科技
 * @department 飞梭BU/研发
 * @description
 * @Email yinxiaopeng@zj.tech
 * @date 2022-03-14 23:05
 */
public enum ConnectorModeEnum {

    TCP_CLIENT("tcp/client", "tcp客户端"),
    TCP_SERVER("tcp/server", "tcp客户端"),
    UDP_SERVER_CLIENT("udp/server_client", "udp"),
    SERIAL_PORT("serialport", "串口"),
    ;

    private String code;
    private String desc;

    ConnectorModeEnum(String code, String desc) {
        this.code = code;
        this.desc = desc;
    }

    public static ConnectorModeEnum of(String code) {
        if (null != code) {
            for (ConnectorModeEnum connectorModeEnum : values()) {
                if (connectorModeEnum.code.equalsIgnoreCase(code)) {
                    return connectorModeEnum;
                }
            }
        }
        throw new IllegalParameterException();
    }

}
